package com.e9ab98e991ab.moduler.ui.pay

import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.RelativeLayout

import com.airbnb.lottie.animation.content.Content
import com.e9ab98e991ab.libcommon.base.BaseActivity
import com.e9ab98e991ab.libcommon.utils.toast.ToastyUtils
import com.e9ab98e991ab.moduler.R
import com.e9ab98e991ab.moduler.R.attr.textSize
import com.e9ab98e991ab.moduler.library.pay.weixin.WXPay
import kotlinx.android.synthetic.main.activity_wx.*
import org.jetbrains.anko.longToast
import org.jetbrains.anko.sp
import org.w3c.dom.Text


class WXActivity : BaseActivity() {

    override fun getLayoutId(): Int {
         return R.layout.activity_wx
    }



    override fun initSet() {
        setTitle(R.string.wechat)

        wxConfirm.setOnClickListener { _: View? ->
            run {
                if (!TextUtils.isEmpty(wxAppId.text) && !TextUtils.isEmpty(wxParam.text.toString())) {
                    doWXPay(wxParam.text.toString(), wxAppId.text.toString())
                }
            }
        }
    }

    override fun initDate() {

    }


    private fun doWXPay(payParam: String,wxAppIP:String) {
        //要在支付前调用
        WXPay.init(this,wxAppIP )

        WXPay.getInstance().doPay(payParam, object : WXPay.WXPayResultCallBack {
            override fun onSuccess() {
                ToastyUtils.success("支付成功")
            }

            override fun onError(errorCode: Int) {
                when (errorCode) {
                    WXPay.NO_OR_LOW_WX -> ToastyUtils.normal("未安装微信或微信版本过低")

                    WXPay.ERROR_PAY_PARAM -> ToastyUtils.error("支付参数错误")
                    WXPay.ERROR_PAY -> ToastyUtils.error("支付失败")
                    else -> {
                    }
                }
            }

            override fun onCancel() {
                ToastyUtils.normal("取消支付")
            }
        })
    }

}